package com.huawei.hms.support.api.push.c.a.a;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build.VERSION;

public class b {
    protected SharedPreferences a;

    public b(Context context, String str) {
        if (context == null) {
            throw new NullPointerException("context is null!");
        }
        if (VERSION.SDK_INT >= 24) {
            Context createDeviceProtectedStorageContext = context.createDeviceProtectedStorageContext();
            SharedPreferences sharedPreferences = createDeviceProtectedStorageContext.getSharedPreferences("move_to_de_records", 0);
            if (!sharedPreferences.getBoolean(str, false)) {
                if (createDeviceProtectedStorageContext.moveSharedPreferencesFrom(context, str)) {
                    Editor edit = sharedPreferences.edit();
                    edit.putBoolean(str, true);
                    edit.commit();
                }
            }
            context = createDeviceProtectedStorageContext;
        }
        this.a = context.getSharedPreferences(str, 0);
    }

    public String a(String str) {
        return this.a != null ? this.a.getString(str, "") : "";
    }

    public boolean a(String str, String str2) {
        if (this.a == null) {
            return false;
        }
        Editor edit = this.a.edit();
        if (edit != null) {
            return edit.putString(str, str2).commit();
        }
        return false;
    }

    public void a(String str, Long l) {
        if (this.a != null) {
            Editor edit = this.a.edit();
            if (edit != null) {
                edit.putLong(str, l.longValue()).commit();
            }
        }
    }

    public void a(String str, boolean z) {
        if (this.a != null) {
            Editor edit = this.a.edit();
            if (edit != null) {
                edit.putBoolean(str, z).commit();
            }
        }
    }

    public boolean b(String str) {
        if (this.a != null && this.a.contains(str)) {
            Editor edit = this.a.edit();
            if (edit != null) {
                return edit.remove(str).commit();
            }
        }
        return false;
    }
}
